// pages/test/test.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    days: [],
    questions: [],
    day: 1,
    que: 10,
    daykey: 1,
    quekey: 1,
    dayflag: 1,
    queflag: 2,
    nowflag: 0,
    totalNumber: 120
  },
  onMytouchEvent (e) {
    let flag = e.detail.flag
    let selectedKey = e.detail.selectKey
    let tempque = this.data.que
    let tempday = this.data.day
    if (flag === 1) {
      tempday = this.data.days[selectedKey]
      tempque = Math.ceil(this.data.totalNumber / tempday / 10) * 10
    }
    if (flag === 2) {
      tempque = this.data.questions[selectedKey]
      tempday = Math.ceil(this.data.totalNumber / tempque)
    }
    let daykey = this.data.days.findIndex((v) => { return v === tempday })
    let quekey = this.data.questions.findIndex((v) => { return v === tempque })
    this.setData({
      nowflag: flag,
      day: tempday,
      que: tempque,
      daykey: daykey,
      quekey: quekey
    })
    // console.log(flag, this.data.daykey, this.data.quekey)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let questions = []
    let days = []
    let count = this.data.totalNumber
    for (let i = 10; i <= count; i += 10) {
      questions.push(i)
      let countday = Math.ceil(count / i)
      if (!days.includes(countday)) {
        days.push(countday)
      }
    }
    this.setData({
      day: Math.ceil(count / 10),
      que: 10,
      days: days,
      questions: questions
    })
    console.log(this.data.days, this.data.questions)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})